/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jogopoo.Grafico;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Point;
import java.awt.Toolkit;
import java.net.URL;

/**
 *Classe que trata a barra de informações
 * @author pererabass
 */
public class BarraInfo {

    public BarraInfo(GrafCenario cenario) {
        sprite = new Image[1]; //background
        this.cenario = cenario;
        pos = new Point();
        this.pos.x = -3;
        this.pos.y = 635;

    }
/**
 * Carrega Imagens antes que o objeto da classe seja instanciado
 * @param component
 * @throws InterruptedException
 */
    public static void carregarImagens(Component component) throws InterruptedException {
        sprite = new Image[3];
        MediaTracker mediaTracker = new MediaTracker(component);


        URL url = BarraInfo.class.getResource("/imagens/barra.png");
        sprite[0] = Toolkit.getDefaultToolkit().getImage(url);
        mediaTracker.addImage(sprite[0], 0);
        URL url2 = BarraInfo.class.getResource("/imagens/vida.png");
        sprite[1] = Toolkit.getDefaultToolkit().getImage(url2);
        mediaTracker.addImage(sprite[1], 0);

        URL url3 = BarraInfo.class.getResource("/imagens/nuclear.png");
        sprite[2] = Toolkit.getDefaultToolkit().getImage(url3);
        mediaTracker.addImage(sprite[2], 0);


        mediaTracker.waitForAll();
    }

    public void desenha(Graphics2D g2) {

        g2.drawImage(BarraInfo.sprite[0], pos.x, pos.y, cenario);
        for (int i = 0; i < cenario.getJanela().getVida(); ++i) {
            g2.drawImage(BarraInfo.sprite[1], pos.x + 900 - i * 28, pos.y + 20, cenario);
        }
        for (int i = 0; i < cenario.getJanela().getMNuclear(); ++i) {
            g2.drawImage(BarraInfo.sprite[2], pos.x + 750 - i * 28, pos.y + 18, cenario);
        }
        Font f = new Font("Calibri", Font.BOLD, 20);
        g2.setColor(Color.red);
        g2.setFont(f);
        g2.drawString("Score: " + Integer.toString(cenario.getJanela().getScore()), 25, pos.y + 30);

        if (cenario.getMsg()) {
            Font f2 = new Font("Calibri", Font.BOLD, 20);
            g2.setFont(f);
            g2.drawString(cenario.getMensagem(), 420, 360);
        }

        if(!cenario.getTimer().getflag()){
            Font f2 = new Font("Calibri", Font.BOLD, 20);
            g2.setFont(f);
            g2.drawString("PAUSE", 450, 360);
        }
    }

    public void incrPosicao(int x, int y) {
        this.pos.x += x;
        this.pos.y += y;
    }
    private GrafCenario cenario;
    private static Image[] sprite;
    private Point pos;
}

